<?php
Connection::getConnect();
$showlist = $this->get('showlist');
if (COUNT($_POST) > 0 && $this->get('getlist'))
{
	$key = $this->get('key');
	$cat2 = $this->get('cat');
	$sort = $this->get('sort');
	$type = $this->get('type');
	$sb = "DESC";
	if($sort)
		$sb = "ASC";
    $sql = "SELECT id.iid, id.name as name, ii.quantity, ii.barcode, ii.retail_price, ii.whole_sale_price, si.item_unit, si.per_unit, iu.name as uname FROM item_details id JOIN item_inventory ii USING(iid) JOIN supplier_item_cost si USING(iid) JOIN item_unit_detail iu USING(imdid) WHERE quantity > 0 AND id.name LIKE '%$key%' AND (icid=$cat2 OR $cat2=0) GROUP BY id.name ORDER BY id.name $sb";
    Connection::setQuery($sql);
    $slist = Connection::fetchAll(MYSQL_ASSOC);
	
	foreach($slist as $list){
		if (($list['quantity'] / $list['per_unit']) < 0.9)
			continue;
		echo '<tr class="ease searches list" iid="' . $list['iid'] . '">' .
			'<td style="width:250px;text-align:left;">&nbsp;' . $list['name'] . '</td>';
		if ($type == 0)
		{
			echo '<td style="width:100px;" class="ui-text-center">&#8369;' . $list['retail_price'] . '</td>' .
				'<td style="width:100px;" class="ui-text-center">' . $list['quantity'] . 'pc</td>';
		} else {
			echo '<td style="width:100px;" class="ui-text-center">&#8369;' . $list['whole_sale_price'] . '</td>' .
				'<td style="width:100px;" class="ui-text-center">' . floor($list['quantity'] / $list['per_unit']) . $list['uname'] . '</td>';
		}
		echo '</tr>';
	 }
	 exit;
}

	$sql = "SELECT *,(SELECT COUNT(base_cat_id) FROM item_category ci WHERE ci.base_cat_id=ic.icid) AS subs FROM item_category ic WHERE base_cat_id=0 LIMIT 6 ";
    Connection::setQuery($sql);
	$categories = Connection::fetchAll(MYSQL_ASSOC);
?>
